home *** CD-ROM | disk | FTP | other *** search
-
-
- ====================
-
- FILEIO.C
-
- ====================
-
-
- /* Listing 8: Fileio benchmark */
-
- #define LSC
-
- /* fileio.c */
-
-
- /* file reading and writing benchmark
- sequentially writes a 65000 byte file on disk
- generates random long numbers
- uses these modulo 65000 to read and write strings of ODDNUM bytes
- with the file handling system of the c package
- the random number generator is set to a specific seed,
- so that all compilers should generate the same code
-
- Fixed by Joel West, April 16, 1987 to use UNIX-standard creat()
- and open() parameters.
- */
-
- #include <stdio.h>
-
- #ifdef LSC
- #include <unix.h>
- #else
- #ifndef MACC /* this is the right way to do it */
- #include <fcntl.h>
- #endif
- #endif
-
- #ifndef MACC
- #define FILEMODE 0666 /* the normal rw-rw-rw */
- #else
- #define FILEMODE 0x7 /* Mac C only */
- #define O_RDONLY 0
- #define O_WRONLY 1
- #define O_RDWR 2
- #endif
-
- #ifdef LSC
- #define abort AbOrT /* Lightspeed C has an 'abort' entry point */
- #endif
-
- #define ERROR -1
- #define READERR 0
- #define OKCLOSE 0
-
- /* For lseek() */
- #define BEG 0
- #define CURR 1
- #define END 2
-
- #define FILESIZE 65000L
- #define COUNT 500
-
- #define C 13849L
- #define A 25173L
- #define ODDNUM 23
-
- long seed = 7L;
- long random (), lseek ();
-
-
-
-
-
-
-
- main ()
- { int i;
- long j, pos;
- int fd;
- char buffer [ODDNUM + 1];
-
- #include "startup.c"
-
- if ((fd = creat ("test.dat", FILEMODE)) == ERROR)
- abort ("Can't create data file\n");
- else
- printf("File opened for sequential writing\n");
-
- for (j = 0; j < FILESIZE; ++j)
- if (write(fd, "x", 1) == ERROR)
- abort ("Unexpected EOF in writing data file\n");
-
- if (close (fd) != OKCLOSE)
- abort ("Error closing data file\n");
- else
- printf ("Normal termination writing data file\n");
-
- if ((fd = open ("test.dat", O_RDWR)) == ERROR)
- abort ("Can't open data file for random reading and
- writing\n");
- else
- printf ("File opened for random reading and writing\n");
-
- for (i = 0; i < COUNT; ++i)
- { j = random (FILESIZE);
- if (j < 0L)
- j = (-j);
- if (FILESIZE - j < ODDNUM)
- continue;
- if ((pos = lseek (fd, j, BEG)) == -1L)
- abort ("Error reading at random offset\n");
- if (read (fd, buffer, ODDNUM) == READERR)
- abort ("Error reading at random offset\n");
- j = random (FILESIZE);
- if (j < 0L)
- j = (-j);
- if (FILESIZE - j < ODDNUM)
- continue;
- if ((pos = lseek (fd, j, BEG)) == -1L)
- abort ("Error seeking to random offset\n");
- if (write (fd, buffer, ODDNUM) == READERR)
- abort ("Error writing at random offset\n");
- }
- if (close (fd) != OKCLOSE)
- abort ("Error closing data file\n");
- else
- printf ("Normal termination from random reading and
- writing\n");
-
- #include "done.c"
- }
-
-
- long random (size)
-
-
-
-
-
-
- long size;
- { seed = seed * A + C;
- return (seed % size);
- }
-
- abort (message)
- char *message;
- { printf (message);
- exit (ERROR);
- }
-
-
- ====================
-
- DONE.C
-
- ====================
-
-
- /* Listing 10: standard termination header */
-
-
- /* done.c */
-
-
- /* End timing */
- time = TickCount() - time;
- printf("ticks=%ld\n",time);
- printf("Press any key to return to FINDER: ");
- getchar();
-
-
- ====================
-
- FIB.C
-
- ====================
-
-
- /* Listing 5: Fib benchmark */
-
- #define LSC
-
- /* Fib.c */
-
- /* Fibonacci benchmark, modified by Joel West, 4/13/87 */
-
- #include <stdio.h>
-
- #ifdef HYPERC
- #include <TBXTypes.h>
- #include <events.h>
- #endif
-
- #define REGISTER
-
- #define NTIMES 10 /* number of times to compute Fibonacci value */
- #define NUMBER 24 /* biggest one we can compute with 16 bits */
-
-
- main() /* compute Fibonacci value */
- { REGISTER short i;
- REGISTER unsigned short value;
- unsigned short fib();
-
- #include "startup.c"
-
- for (i = 1; i <= NTIMES; i++)
- value = fib(NUMBER);
-
- #include "done.c"
-
- exit(0);
- }
-
-
- unsigned short fib(x) /* compute Fibonacci number recursively */
- REGISTER short x;
- { if (x > 2)
- return (fib(x - 1) + fib(x - 2));
- else
- return (1);
- }
-
-
- ====================
-
- FLOAT.C
-
- ====================
-
-
- /* Listing 7: Float benchmark */
-
- #define LSC
-
- /* float.c */
-
- /* simple benchmark for testing floating point speed of c libraries
- does repeated multiplications and divisions in a loop that is
- large enough to make the looping time insignificant */
-
- #include <stdio.h>
-
- #ifdef MACC
- #define EXTENDED extended
- #else
- #ifdef HYPERC
- #define EXTENDED extended
- #include <TBXTypes.h>
- #include <events.h>
- #else
- #define EXTENDED double
- #endif
- #endif
-
-
- #define CONST1 3.141597E0
- #define CONST2 1.7839032E4
- #define COUNT 10000
-
- main()
- { EXTENDED a, b, c;
- int i;
-
- #include "startup.c"
-
- a = CONST1;
- b = CONST2;
- for (i = 0; i < COUNT; ++i)
- { c = a * b;
- c = c / a;
- c = a * b;
- c = c / a;
- c = a * b;
- c = c / a;
- c = a * b;
- c = c / a;
- c = a * b;
- c = c / a;
- c = a * b;
- c = c / a;
- c = a * b;
- c = c / a;
- }
-
-
- #include "done.c"
- }